package com.taloub.hamza.myfirstapp;

import java.util.Random;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputType;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;

public class TextPlay extends Activity {

	Button chkCmd;
	ToggleButton passTog;
	EditText input;
	TextView display;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.text);

		chkCmd = (Button) findViewById(R.id.chkCmd);
		passTog = (ToggleButton) findViewById(R.id.tbPassword);
		input = (EditText) findViewById(R.id.etCommand);
		display = (TextView) findViewById(R.id.tvResult);

		passTog.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (passTog.isChecked()) {
					input.setInputType(InputType.TYPE_CLASS_TEXT
							| InputType.TYPE_TEXT_VARIATION_PASSWORD);
				} else {
					input.setInputType(InputType.TYPE_CLASS_TEXT);
				}

			}
		});

		chkCmd.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String check = input.getText().toString();

				if (check.contentEquals("center")) {
					display.setGravity(Gravity.CENTER);
					display.setText("center");
				} else if (check.contentEquals("left")) {
					display.setGravity(Gravity.LEFT);
					display.setText("left");
				} else if (check.contentEquals("right")) {
					display.setGravity(Gravity.RIGHT);
					display.setText("right");
				} else if (check.contentEquals("blue")) {
					display.setTextColor(Color.BLUE);
				} else if (check.contentEquals("WTF")) {
					Random crazy = new Random();
					display.setText("WTF!!");
					display.setTextSize(crazy.nextInt(75));
					display.setTextColor(Color.rgb(crazy.nextInt(255),
							crazy.nextInt(255), crazy.nextInt(255)));
					switch (crazy.nextInt(3)) {
					case 0:
						display.setGravity(Gravity.CENTER);
						break;
					case 1:
						display.setGravity(Gravity.LEFT);
						break;
					case 2:
						display.setGravity(Gravity.RIGHT);
						break;

					}
				} else {
					display.setText("invalid");
					display.setGravity(Gravity.CENTER);
					display.setTextColor(Color.GRAY);
				}

			}
		});
	}

}
